package com.application.format;

import java.io.Serializable;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.application.iface.IMessage;

@Component("StdMessage")
public class StdMessage implements IMessage,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public final static String MTYPE_REQUEST = "REQ";
	public final static String MTYPE_RESPONSE = "RSP";
	
	public String uniqueId;
	
	public String msgType = MTYPE_REQUEST;
	
	public Date createTime = new Date();
	
	public int deliveryTime = 0;
	
	public SysHeader sysHeader;
	
	public AppHeader appHeader;
	
	public Object context;

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getMsgType() {
		return msgType;
	}

	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public int getDeliveryTime() {
		return deliveryTime;
	}

	public void setDeliveryTime(int deliveryTime) {
		this.deliveryTime = deliveryTime;
	}

	public SysHeader getSysHeader() {
		return sysHeader;
	}

	public void setSysHeader(SysHeader sysHeader) {
		this.sysHeader = sysHeader;
	}

	public AppHeader getAppHeader() {
		return appHeader;
	}

	public void setAppHeader(AppHeader appHeader) {
		this.appHeader = appHeader;
	}

	public Object getContext() {
		return context;
	}

	public void setContext(Object context) {
		this.context = context;
	}

	public String getSerivceId() {
		return sysHeader.getServiceId();
	}

	public Object getBody() {
		return context;
	}

	/* (non-Javadoc)
	 * @see com.application.iface.IMessage#isHeartbeat()
	 */
	@Override
	public boolean isHeartbeat() {		
		return "999999".equals(sysHeader.getServiceId());
	}

	/* (non-Javadoc)
	 * @see com.application.iface.IMessage#isRequest()
	 */
	@Override
	public boolean isRequest() {
		return MTYPE_REQUEST.equals(msgType);
	}

	/* (non-Javadoc)
	 * @see com.application.iface.IMessage#isResponse()
	 */
	@Override
	public boolean isResponse() {
		return MTYPE_RESPONSE.equals(msgType);
	}


}
